const app = getApp()
const request = require('../../../utils/api.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: [{
        name: 'tab1',
        count: 100.00,
        gift: 3500,
        flag: false,
        idx: 0
      },
      {
        name: 'tab2',
        count: 50.00,
        gift: 1500,
        flag: false,
        idx: 1
      },
      {
        name: 'tab3',
        count: 10.00,
        gift: 800,
        flag: false,
        idx: 2
      },
      {
        name: 'tab4',
        count: 30.00,
        gift: 300,
        flag: false,
        idx: 3
      }
    ],
    submit: false
  },

   onLoad: function() {
    
    const data = {
      //接口測試
      url: '/v3_1/print/print_record',
      method: 'POST',
      datas: {
        'type': 2, // 1照片记录 2文档记录
        'pageNum': 1,
        'pageSize': 15
      }
    }
    request(data).then(success => {
      console.log(success)
      if (success.data.code === 200) {
        if (success.data.data.bind_result === 1) {
          wx.showToast({
            title: success.data.data.bind_result_desc,
            icon: 'success',
            duration: 2000,
          }) 
        } else {
          wx.showToast({
            title: success.data.data.bind_result_desc,
            icon: 'loading',
            duration: 2000,
          })
 
        }
      } else if (success.data.code === 6000) {
        wx.showToast({
          title: success.data.message,
          icon: 'loading',
          duration: 2000,
         
        })
      } else {
        console.log(success)
        that.setData({
          isBind: false,
          deviceName: '',
   
        })
        wx.showToast({
          title: success.data.message,
          icon: 'none',
          duration: 2000,
        })
      }
    }).catch(error => {
      wx.showToast({
        title: error,
        icon: 'none',
        duration: 2000,
      })

     })




   },

//   pickTab: function(e) { // 点击tab
//     let flag = this.data.tab[e.currentTarget.dataset.idx].flag
//     let newTab = []
//     for (let v of this.data.tab) { // 组装数据
//       if (v.idx === e.currentTarget.dataset.idx) {
//         v.flag = !flag
//       } else {
//         v.flag = false
//       }
//       newTab.push(v)
//     }
//     this.setData({
//       tab: newTab,
//       submit: !flag
//     })
//   },
//   submit: function() {
//     if (!this.data.submit) {
//       wx.showToast({
//         title: '请选择金额',
//         icon: 'none',
//         duration: 2000
//       })
//       return
//     }
//     wx.showToast({
//       title: '充值成功',
//       icon: 'none',
//       duration: 2000
//     })
//   }
 })